﻿using System;
using Close.io.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Close.io.UnitTests
{
	[TestClass]
	public class FieldBuilderTests
	{
		[TestMethod]
		public void TestFieldBuilder()
		{

			var leadFields = CloseIoFields<Lead>.Add(p => p.Name);

			Assert.AreEqual( "Name" ,leadFields.ToString());

			leadFields = CloseIoFields<Lead>.Add(p => p.Name).Add(p=>p.Description);

			Assert.AreEqual("Name,Description", leadFields.ToString());

			leadFields = CloseIoFields<Lead>.Add(p => p.Name).Add(p => p.Description).Add(p=>p.Custom);

			Assert.AreEqual("Name,Description,Custom", leadFields.ToString());


			var contactFields = CloseIoFields<Contact>.Add(p => p.Name).Add(p => p.Title).Add(p => p.Phones);

			Assert.AreEqual( "Name,Title,Phones", contactFields.ToString());
			 

		}
	}

	[TestClass]
	public class UpdateBuilderTests
	{
		[TestMethod]
		public void TestUpdateBuilder()
		{

			var updateFields = CloseIoUpdate<Lead>.Add(p => p.Name,"Gary");

			Assert.AreEqual("{\"name\":\"Gary\"}",updateFields.GetUpdateJson());

			updateFields = CloseIoUpdate<Lead>.Add(p => p.Name, "Gary").Add(p=>p.Description,"Test");

			Assert.AreEqual( "{\"name\":\"Gary\",\"description\":\"Test\"}",updateFields.GetUpdateJson());

			updateFields.AddCustomFieldUpdate("Industry", "Advertising");

			Assert.AreEqual( "{\"name\":\"Gary\",\"description\":\"Test\",\"custom.Industry\":\"Advertising\"}",updateFields.GetUpdateJson());

		}
	}
}
